﻿using d1Project.Tools.JsonParse;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace d1Project.Modules.Common.do4A.Models
{
    public class Permission
    {
        public Permission(string _moduleId, doJsonNode _jsonNode)
        {
            this.loadData(_moduleId, _jsonNode);
        }

        private void loadData(string _moduleId, doJsonNode _jsonNode)
        {
            this.PermissionId = _moduleId + "$" + _jsonNode.GetOneText("Id", "");
            this.PermissionName = _jsonNode.GetOneText("Name", "");
            List<doJsonNode> _operations = _jsonNode.GetOneNodeArray("Operations");
            if (_operations == null || _operations.Count <= 0) return;
            this.Operations = new List<Operation>();
            foreach (doJsonNode _nodeOperation in _operations)
            {
                this.Operations.Add(new Operation(_nodeOperation));
            }
        }

        /// <summary>
        /// 权限Id
        /// </summary>
        public string PermissionId { get; private set; }

        /// <summary>
        /// 名称
        /// </summary>
        public string PermissionName { get; private set; }

        /// <summary>
        /// 操作集合
        /// </summary>
        public List<Operation> Operations
        {
            get;
            private set;
        }

        public int OperationsValue;

    }
}